'use strict';

var underscore = angular.module('underscore', []);
underscore.factory('_', function() {
  return window._;
});

angular.module("template/popover/popover.html", []).run(["$templateCache", function ($templateCache) {
    $templateCache.put("template/popover/popover.html",
      "<div class=\"popover {{placement}}\" ng-class=\"{ in: isOpen(), fade: animation() }\">\n" +
      "  <div class=\"arrow\"></div>\n" +
      "\n" +
      "  <div class=\"popover-inner\">\n" +
      "      <h3 class=\"popover-title\" ng-bind-html=\"title | unsafe\" ng-show=\"title\"></h3>\n" +
      "      <div class=\"popover-content\"ng-bind-html=\"$compile(content)(scope)\"></div>\n" +
      "  </div>\n" +
      "</div>\n" +
      "");
}]);

var app = angular
  .module('afasApp', [
    'ngCookies',
    'ngResource',
    'ngSanitize',
    'ui.router',
    'LocalStorageModule',
    'ui.bootstrap',
    'angularFileUpload',
    'underscore',
    'ui.bootstrap-slider',
    'pageslide-directive',
    'angularUtils.directives.dirPagination',
    'cgBusy',
    'dialogs.main'
  ]);


app.config(['$stateProvider', '$controllerProvider', '$locationProvider', '$urlRouterProvider', function ($stateProvider, $controllerProvider, $locationProvider, $urlRouterProvider) {
  app.controller = $controllerProvider;

  $urlRouterProvider.otherwise('/');
  $stateProvider.state('site', {
    'abstract': true,
    templateUrl: 'views/container.html',
    resolve: {
      authorize: ['authorization',
        function(authorization) {
          return authorization.authorize();
        }
      ]
    }
  })
  .state('misc', {
    'abstract': true,
    templateUrl: 'views/misc.html',
    resolve: {
      authorize: ['authorization',
        function(authorization) {
          return authorization.authorize();
        }
      ]
    }
  })
  .state('misc.payments', {
    parent: 'misc',
    abstract: true,
    url: '/misc/payments',
    templateUrl: 'views/modules/payment/payment.index.html'
  })
  .state('misc.payments.print', {
    url: '/:id/print',
    views: {
      'main': {
        templateUrl: 'views/modules/payment/payment.misc.print.html',
        controller: 'PaymentSingleCtrl'
      }
    },
    data: {
      roles: ['GetPayments']
    }
  })
  .state('home', {
    parent: 'site',
    url: '/',
    views: {
      templateUrl: 'views/main.html'
    },
    data: {
      displayName: false,
      roles: ['GetUsers']
    }
  })
  .state('login', {
    // parent: 'site',
    url: '/login',
    templateUrl: 'views/login.html',
    controller: 'SigninCtrl',
    data: {
      displayName: false,
      roles: []
    }
  })

  // #RECEPTIONIST MODULE
  // .state('receptionist', {
  //   url: '/receptionist',
  //   templateUrl: 'views/modules/index.html'
  // })

  // #NOTE
  // .state('pt.show', {
  //   url: '/:id',
  //   views: {
  //     'main': {
  //       templateUrl: 'views/modules/pt/pt.show.html',
  //       controller: 'PTsingleCtrl'
  //     }
  //   },
  //   data: {
  //     displayName: '{{ pt.data.Student.FullName }} - {{ pt.data.DateTime | date: medium }}',
  //     roles: ['GetUsers']
  //   },
  //   resolve: {
  //     pt : ['$stateParams', 'Services', function($stateParams, Services) {
  //       return Services.getItem('placement_tests', $stateParams.id);
  //     }]
  //   }
  // })
  // .state('pt.show.edit', {
  //   url: '/edit',
  //   views: {
  //     'sub': {
  //       templateUrl: 'views/modules/pt/pt.edit.html'
  //     }
  //   },
  //   data: {
  //     displayName: 'edit',
  //     roles: ['GetUsers']
  //   }
  // })

  // ================MASTER============ #START

  //#STUDENT
  .state('students', {
    parent: 'site',
    abstract: true,
    url: '/students',
    templateUrl: 'views/masters/students/students.index.html',
    data: {
      breadcrumbProxy: 'students.list'
    }
  })
  .state('students.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.list.html',
        controller: 'StudentsCtrl'
      }
    },
    data: {
      displayName: 'Students',
      roles: ['GetStudents']
    }
  })
  .state('students.new', {
    url: '/new/{name}',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.create.html',
        controller: 'StudentsCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostStudents']
    }
  })
  .state('students.searchList', {
    url: '/search/:key',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.list.html',
        controller: 'StudentsCtrl'
      }
    },
    data: {
      displayName: '',
      roles: ['GetStudents']
    }
  })
  .state('students.blocked', {
    url: '/blocked',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.blocked.html',
        controller: 'StudentsBlockedCtrl'
      }
    },
    data: {
      displayName: 'Blocked',
      roles: ['GetStudents']
    }
  })
  .state('students.searchBlocked', {
    url: '/blocked/search/:key',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.blocked.html',
        controller: 'StudentsBlockedCtrl'
      }
    },
    data: {
      displayName: 'Blocked',
      roles: ['GetStudents']
    }
  })
  .state('students.refund', {
    url: '/refund',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.refund.html',
        controller: 'StudentsRefundCtrl'
      }
    },
    data: {
      displayName: 'Refund',
      roles: ['GetRefunds']
    }
  })
  .state('students.searchRefund', {
    url: '/refund/search/:key',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.refund.html',
        controller: 'StudentsRefundCtrl'
      }
    },
    data: {
      displayName: 'Refund',
      roles: ['GetRefunds']
    }
  })
  .state('students.discount', {
    url: '/discount',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.discount.html',
        controller: 'StudentsDiscountCtrl'
      }
    },
    data: {
      displayName: 'Discount',
      roles: ['GetStudentDiscounts']
    }
  })
  .state('students.searchDiscount', {
    url: '/discount/search/:key',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.discount.html',
        controller: 'StudentsDiscountCtrl'
      }
    },
    data: {
      displayName: 'Discount',
      roles: ['GetStudentDiscounts']
    }
  })
  .state('students.unpaid', {
    url: '/unpaid',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.unpaid.html',
        controller: 'StudentsUnpaidCtrl'
      }
    },
    data: {
      displayName: 'Unpaid Registration',
      roles: ['GetStudents']
    }
  })
  .state('students.searchUnpaid', {
    url: '/unpaid/search/:key',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.unpaid.html',
        controller: 'StudentsUnpaidCtrl'
      }
    },
    data: {
      displayName: 'Unpaid',
      roles: ['GetStudents']
    }
  })
  .state('students.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/students/students.show.html',
        controller: 'StudentCtrl'
      }
    },
    data: {
      displayName: '{{ student.data.FullName }}',
      roles: ['GetStudents']
    },
    resolve: {
      student : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('students', $stateParams.id);
      }]
    }
  })
  .state('students.show.edit', {
    url: '/edit',
    views: {
      'sub': {
        templateUrl: 'views/masters/students/students.edit.html'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutStudents']
    }
  })
  .state('students.individual', {
    url: '/report/:id',
    views: {
      'main': {
        templateUrl: 'views/reports/report.individual.html',
        controller: 'StudentReportCtrl'
      }
    },
    data: {
      displayName: '{{ student.data.CourseSchedule.Course.CourseLevel.Name }}',
      roles: ['GetStudents']
    },
    resolve: {
      student : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('enrollments', $stateParams.id);
      }]
    }
  })

  //#COUNTRY
  .state('countries', {
    parent: 'site',
    abstract: true,
    url: '/countries',
    templateUrl: 'views/masters/countries/countries.index.html',
    data: {
      breadcrumbProxy: 'countries.list'
    }
  })
  .state('countries.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/countries/countries.list.html',
        controller: 'CountriesCtrl'
      }
    },
    data: {
      displayName: 'Countries',
      roles: ['GetCountries']
    }
  })
  .state('countries.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/countries/countries.create.html',
        controller: 'CountriesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostCountries']
    }
  })
  .state('countries.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/countries/countries.show.html',
        controller: 'CountryCtrl'
      }
    },
    data: {
      displayName: '{{ country.data.Name }}',
      roles: ['GetCountries']
    },
    resolve: {
      country : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('countries', $stateParams.id);
      }]
      }
  })
  .state('countries.show.edit', {
    url: '/edit',
    views: {
      'sub': {
        templateUrl: 'views/masters/countries/countries.edit.html'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutCountries']
    }
  })

  //#SEX
  .state('sexes', {
    parent: 'site',
    abstract: true,
    url: '/sexes',
    templateUrl: 'views/masters/sexes/sexes.index.html',
    data: {
      breadcrumbProxy: 'sexes.list'
    }
  })
  .state('sexes.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/sexes/sexes.list.html',
        controller: 'SexesCtrl'
      }
    },
    data: {
      displayName: 'Sexes',
      roles: ['GetSexes']
    }
  })
  .state('sexes.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/sexes/sexes.create.html',
        controller: 'SexesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['CreateSexes']
    }
  })
  .state('sexes.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/sexes/sexes.show.html',
        controller: 'SexCtrl'
      }
    },
    data: {
      displayName: '{{ sex.SexLabel }}',
      roles: ['GetSexes']
    },
    resolve: {
      sex : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('sexes' ,$stateParams.id);
      }]
    }
  })
  .state('sexes.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/sexes/sexes.edit.html',
        controller: 'SexCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutSexes']
    }
  })

  //#CITY
  .state('cities', {
    parent: 'site',
    abstract: true,
    url: '/cities',
    templateUrl: 'views/masters/cities/cities.index.html',
    data: {
      breadcrumbProxy: 'cities.list'
    }
  })
  .state('cities.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/cities/cities.list.html',
        controller: 'CitiesCtrl'
      }
    },
    data: {
      displayName: 'Cities',
      roles: ['GetCities']
    }
  })
  .state('cities.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/cities/cities.create.html',
        controller: 'CitiesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['NewCities']
    }
  })
  .state('cities.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/cities/cities.show.html',
        controller: 'CityCtrl'
      }
    },
    data: {
      displayName: '{{ city.CityName }}',
      roles: ['GetCities']
    },
    resolve: {
      city : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('cities' ,$stateParams.id);
      }]
    }
  })
  .state('cities.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/cities/cities.edit.html',
        controller: 'CityCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutCities']
    }
  })

  //#CURRENCY
  .state('currencies', {
    parent: 'site',
    abstract: true,
    url: '/currencies',
    templateUrl: 'views/masters/currencies/currencies.index.html',
    data: {
      breadcrumbProxy: 'currencies.list'
    }
  })
  .state('currencies.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/currencies/currencies.list.html',
        controller: 'CurrenciesCtrl'
      }
    },
    data: {
      displayName: 'Currencies',
      roles: ['GetCurrencies']
    }
  })
  .state('currencies.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/currencies/currencies.create.html',
        controller: 'CurrenciesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostCurrencies']
    }
  })
  .state('currencies.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/currencies/currencies.show.html',
        controller: 'CurrencyCtrl'
      }
    },
    data: {
      displayName: '{{ currency.CurrencyName }}',
      roles: ['GetCurrencies']
    },
    resolve: {
      currency : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('currencies' ,$stateParams.id);
      }]
    }
  })
  .state('currencies.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/currencies/currencies.edit.html',
        controller: 'CurrencyCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutCurrencies']
    }
  })

  //#PROVINCE
  .state('provinces', {
    parent: 'site',
    abstract: true,
    url: '/provinces',
    templateUrl: 'views/masters/provinces/provinces.index.html',
    data: {
      breadcrumbProxy: 'provinces.list'
    }
  })
  .state('provinces.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/provinces/provinces.list.html',
        controller: 'ProvincesCtrl'
      }
    },
    data: {
      displayName: 'Provinces',
      roles: ['GetProvinces']
    }
  })
  .state('provinces.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/provinces/provinces.create.html',
        controller: 'ProvincesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostCurrencies']
    }
  })
  .state('provinces.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/provinces/provinces.show.html',
        controller: 'ProvinceCtrl'
      }
    },
    data: {
      displayName: '{{ province.ProvinceName }}',
      roles: ['GetCurrencies']
    },
    resolve: {
      province : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('provinces', $stateParams.id);
      }]
    }
  })
  .state('provinces.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/provinces/provinces.edit.html',
        controller: 'ProvinceCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutProvinces']
    }
  })

  //#CONTACTTYPE
  .state('contacttypes', {
    parent: 'site',
    abstract: true,
    url: '/contacttypes',
    templateUrl: 'views/masters/contact-types/contact.types.index.html',
    data: {
      breadcrumbProxy: 'contacttypes.list'
    }
  })
  .state('contacttypes.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/contact-types/contact.types.list.html',
        controller: 'ContactTypesCtrl'
      }
    },
    data: {
      displayName: 'Contact Types',
      roles: ['GetContactTypes']
    }
  })
  .state('contacttypes.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/contact-types/contact.types.create.html',
        controller: 'ContactTypesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostContactTypes']
    }
  })
  .state('contacttypes.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/contact-types/contact.types.show.html',
        controller: 'ContactTypeCtrl'
      }
    },
    data: {
      displayName: '{{ contactType.data.Name }}',
      roles: ['GetContactTypes']
    },
    resolve: {
      contactType : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('contact_types', $stateParams.id);
      }]
    }
  })
  .state('contacttypes.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/contact-types/contact.types.edit.html',
        controller: 'ContactTypeCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutContactTypes']
    }
  })

  //#AMOUNTTYPE
  .state('amounttypes', {
    parent: 'site',
    abstract: true,
    url: '/amounttypes',
    templateUrl: 'views/masters/amount-types/amount.types.index.html',
    data: {
      breadcrumbProxy: 'amounttypes.list'
    }
  })
  .state('amounttypes.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/amount-types/amount.types.list.html',
        controller: 'AmountTypesCtrl'
      }
    },
    data: {
      displayName: 'Amount Types',
      roles: ['GetAmountTypes']
    }
  })
  .state('amounttypes.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/amount-types/amount.types.create.html',
        controller: 'AmountTypesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostAmountTypes']
    }
  })
  .state('amounttypes.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/amount-types/amount.types.show.html',
        controller: 'AmountTypeCtrl'
      }
    },
    data: {
      displayName: '{{ amountType.AmountTypeLabel }}',
      roles: ['GetAmountTypes']
    },
    resolve: {
      amountType : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('amounttypes', $stateParams.id);
      }]
    }
  })
  .state('amounttypes.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/amount-types/amount.types.edit.html',
        controller: 'AmountTypeCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutAmountTypes']
    }
  })

  //#CONTACTS
  .state('contacts', {
    parent: 'site',
    abstract: true,
    url: '/contacts',
    templateUrl: 'views/masters/contacts/contacts.index.html',
    data: {
      breadcrumbProxy: 'contacts.list'
    }
  })
  .state('contacts.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/contacts/contacts.list.html',
        controller: 'ContactsCtrl'
      }
    },
    data: {
      displayName: 'Contacts',
      roles: ['GetContacts']
    }
  })
  .state('contacts.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/contacts/contacts.create.html',
        controller: 'ContactsCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostContacts']
    }
  })
  .state('contacts.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/contacts/contacts.show.html',
        controller: 'ContactCtrl'
      }
    },
    data: {
      displayName: 'contact',
      roles: ['GetContacts']
    // },
    }
    // resolve: {
    //   contact : ['$stateParams', 'contacts', function($stateParams, contacts) {
    //     return contacts.getcontact($stateParams.id);
    //   }]
    // }
  })
  .state('contacts.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/contacts/contacts.edit.html',
        controller: 'ContactCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutContacts']
    }
  })

  // #ADMIN MODULE
  .state('admin', {
    url: '/admin',
    templateUrl: 'views/modules/index.html'
  })

  //#USER
  .state('users', {
    parent: 'site',
    abstract: true,
    url: '/users',
    templateUrl: 'views/masters/users/users.index.html',
    data: {
      breadcrumbProxy: 'users.list'
    }
  })
  .state('users.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/users/users.list.html',
        controller: 'UsersCtrl'
      }
    },
    data: {
      displayName: 'Users',
      roles: ['GetUsers']
    }
  })
  .state('users.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/users/users.create.html',
        controller: 'UsersCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostUsers']
    }
  })
  .state('users.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/users/users.show.html',
        controller: 'UserCtrl'
      }
    },
    data: {
      displayName: '{{ user.data.Username }}',
      roles: ['GetUsers']
    },
    resolve: {
      user : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('users', $stateParams.id);
      }]
    }
  })
  .state('users.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/users/users.edit.html',
        controller: 'UserCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutUsers']
    }
  })

  //#ROOM
  .state('rooms', {
    parent: 'site',
    abstract: true,
    url: '/rooms',
    templateUrl: 'views/masters/rooms/rooms.index.html',
    data: {
      breadcrumbProxy: 'rooms.list'
    }
  })
  .state('rooms.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/rooms/rooms.list.html',
        controller: 'RoomsCtrl'
      }
    },
    data: {
      displayName: 'Classrooms',
      roles: ['GetRooms']
    }
  })
  .state('rooms.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/rooms/rooms.create.html',
        controller: 'RoomsCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostRooms']
    }
  })
  .state('rooms.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/rooms/rooms.show.html',
        controller: 'RoomCtrl'
      }
    },
    data: {
      displayName: '{{ room.Name }}',
      roles: ['GetRooms']
    },
    resolve: {
      room : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('classrooms', $stateParams.id);
      }]
    }
  })
  .state('rooms.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/rooms/rooms.edit.html',
        controller: 'RoomCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutRooms']
    }
  })

  //#TEACHERS
  .state('teachers', {
    parent: 'site',
    abstract: true,
    url: '/teachers',
    templateUrl: 'views/masters/teachers/teachers.index.html',
    data: {
      breadcrumbProxy: 'teachers.list'
    }
  })
  .state('teachers.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/teachers/teachers.list.html',
        controller: 'TeachersCtrl'
      }
    },
    data: {
      displayName: 'Teachers',
      roles: ['GetStaffs']
    }
  })
  .state('teachers.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/teachers/teachers.create.html',
        controller: 'TeachersCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostStaffs']
    }
  })
  .state('teachers.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/teachers/teachers.show.html',
        controller: 'TeacherCtrl'
      }
    },
    data: {
      displayName: '{{ teacher.data.Name }}',
      roles: ['GetStaffs']
    },
    resolve: {
      teacher : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('staffs', $stateParams.id);
      }]
    }
  })
  .state('teachers.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/teachers/teachers.edit.html',
        controller: 'TeacherCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutStaffs']
    }
  })

  //#TERMS
  .state('terms', {
    parent: 'site',
    abstract: true,
    url: '/terms',
    templateUrl: 'views/masters/terms/terms.index.html',
    data: {
      breadcrumbProxy: 'terms.list'
    }
  })
  .state('terms.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/terms/terms.list.html',
        controller: 'TermsCtrl'
      }
    },
    data: {
      displayName: 'Terms',
      roles: ['GetTerms']
    }
  })
  .state('terms.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/terms/terms.create.html',
        controller: 'TermsCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostTerms']
    }
  })
  .state('terms.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/terms/terms.show.html',
        controller: 'TermCtrl'
      }
    },
    data: {
      displayName: '{{ term.Term }} / {{ term.Year }}',
      roles: ['GetTerms']
    },
    resolve: {
      term : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('terms', $stateParams.id);
      }]
    }
  })
  .state('terms.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/terms/terms.edit.html',
        controller: 'TermCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutTerms']
    }
  })

  //#COURSE TYPES
  .state('coursetypes', {
    parent: 'site',
    abstract: true,
    url: '/coursetypes',
    templateUrl: 'views/masters/course-types/course.types.index.html',
    data: {
      breadcrumbProxy: 'coursetypes.list'
    }
  })
  .state('coursetypes.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/course-types/course.types.list.html',
        controller: 'CourseTypesCtrl'
      }
    },
    data: {
      displayName: 'Course Types',
      roles: ['GetCourseTypes']
    }
  })
  .state('coursetypes.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/course-types/course.types.create.html',
        controller: 'CourseTypesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostCourseTypes']
    }
  })
  .state('coursetypes.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/course-types/course.types.show.html',
        controller: 'CourseTypeCtrl'
      }
    },
    data: {
      displayName: '{{ coursetype.data.Name }}',
      roles: ['GetCourseTypes']
    },
    resolve: {
      coursetype : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('course_types', $stateParams.id);
      }]
    }
  })
  .state('coursetypes.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/course-types/course.types.edit.html',
        controller: 'CourseTypeCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutCourseTypes']
    }
  })

  //#DAY CLASSES
  .state('dayclasses', {
    parent: 'site',
    abstract: true,
    url: '/dayclasses',
    templateUrl: 'views/masters/day-classes/day.classes.index.html',
    data: {
      breadcrumbProxy: 'dayclasses.list'
    }
  })
  .state('dayclasses.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/day-classes/day.classes.list.html',
        controller: 'DayClassesCtrl'
      }
    },
    data: {
      displayName: 'Day Classes',
      roles: ['GetDayClasses']
    }
  })
  .state('dayclasses.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/day-classes/day.classes.create.html',
        controller: 'DayClassesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostDayClasses']
    }
  })
  .state('dayclasses.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/day-classes/day.classes.show.html',
        controller: 'DayClassCtrl'
      }
    },
    data: {
      displayName: '{{ dayclasses.DayClassLabel }}',
      roles: ['GetDayClasses']
    },
    resolve: {
      dayclasses : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('dayclasses', $stateParams.id);
      }]
    }
  })
  .state('dayclasses.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/day-classes/day.classes.edit.html',
        controller: 'DayClassCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutDayClasses']
    }
  })

  //#TIME CLASSES
  .state('timeclasses', {
    parent: 'site',
    abstract: true,
    url: '/timeclasses',
    templateUrl: 'views/masters/time-classes/time.classes.index.html',
    data: {
      breadcrumbProxy: 'timeclasses.list'
    }
  })
  .state('timeclasses.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/time-classes/time.classes.list.html',
        controller: 'TimeClassesCtrl'
      }
    },
    data: {
      displayName: 'Time Classes',
      roles: ['GetTimeClasses']
    }
  })
  .state('timeclasses.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/time-classes/time.classes.create.html',
        controller: 'TimeClassesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostTimeClasses']
    }
  })
  .state('timeclasses.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/time-classes/time.classes.show.html',
        controller: 'TimeClassCtrl'
      }
    },
    data: {
      displayName: '{{ timeclasses.data.Label }}',
      roles: ['GetTimeClasses']
    },
    resolve: {
      timeclasses : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('time_classes', $stateParams.id);
      }]
    }
  })
  .state('timeclasses.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/time-classes/time.classes.edit.html',
        controller: 'TimeClassCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutTimeClasses']
    }
  })

  //#DISCOUNTS
  .state('discounts', {
    parent: 'site',
    abstract: true,
    url: '/discounts',
    templateUrl: 'views/masters/discounts/disc.index.html',
    data: {
      breadcrumbProxy: 'discounts.list'
    }
  })
  .state('discounts.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/discounts/disc.list.html',
        controller: 'DiscountsCtrl'
      }
    },
    data: {
      displayName: 'Discounts',
      roles: ['GetDiscounts']
    }
  })
  .state('discounts.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/discounts/disc.create.html',
        controller: 'DiscountsCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostDiscounts']
    }
  })
  .state('discounts.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/discounts/disc.show.html',
        controller: 'DiscountCtrl'
      }
    },
    data: {
      displayName: '{{ discounts.TimeClassLabel }}',
      roles: ['GetDiscounts']
    },
    resolve: {
      discounts : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('discounts', $stateParams.id);
      }]
    }
  })
  .state('discounts.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/discounts/disc.edit.html',
        controller: 'DiscountCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutDiscounts']
    }
  })

  //#STAFFS
  .state('staffs', {
    parent: 'site',
    abstract: true,
    url: '/staffs',
    templateUrl: 'views/masters/staffs/staffs.index.html',
    data: {
      breadcrumbProxy: 'staffs.list'
    }
  })
  .state('staffs.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/staffs/staffs.list.html',
        controller: 'StaffsCtrl'
      }
    },
    data: {
      displayName: 'Staffs',
      roles: ['GetStaffs']
    }
  })
  .state('staffs.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/staffs/staffs.create.html',
        controller: 'StaffsCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostStaffs']
    }
  })
  .state('staffs.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/staffs/staffs.show.html',
        controller: 'StaffCtrl'
      }
    },
    data: {
      displayName: '{{ staffs.TimeClassLabel }}',
      roles: ['GetStaffs']
    },
    resolve: {
      staffs : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('staffs', $stateParams.id);
      }]
    }
  })
  .state('staffs.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/staffs/staffs.edit.html',
        controller: 'StaffCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutStaffs']
    }
  })

  //#AGE GROUPS
  .state('agegroups', {
    parent: 'site',
    abstract: true,
    url: '/agegroups',
    templateUrl: 'views/masters/agegroups/age.groups.index.html',
    data: {
      breadcrumbProxy: 'agegroups.list'
    }
  })
  .state('agegroups.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/agegroups/age.groups.list.html',
        controller: 'AgeGroupsCtrl'
      }
    },
    data: {
      displayName: 'Age Groups',
      roles: ['GetAgeGroups']
    }
  })
  .state('agegroups.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/agegroups/age.groups.create.html',
        controller: 'AgeGroupsCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostAgeGroups']
    }
  })
  .state('agegroups.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/agegroups/age.groups.show.html',
        controller: 'AgeGroupCtrl'
      }
    },
    data: {
      displayName: '{{ agegroups.AgeGroup }}',
      roles: ['GetAgeGroups']
    },
    resolve: {
      agegroups : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('agegroups', $stateParams.id);
      }]
    }
  })
  .state('agegroups.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/agegroups/age.groups.edit.html',
        controller: 'AgeGroupCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutAgeGroups']
    }
  })

  //#BANKS
  .state('banks', {
    parent: 'site',
    abstract: true,
    url: '/banks',
    templateUrl: 'views/masters/banks/banks.index.html',
    data: {
      breadcrumbProxy: 'banks.list'
    }
  })
  .state('banks.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/banks/banks.list.html',
        controller: 'BanksCtrl'
      }
    },
    data: {
      displayName: 'Banks',
      roles: ['GetBanks']
    }
  })
  .state('banks.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/banks/banks.create.html',
        controller: 'BanksCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostBanks']
    }
  })
  .state('banks.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/banks/banks.show.html',
        controller: 'BankCtrl'
      }
    },
    data: {
      displayName: '{{ banks.TimeClassLabel }}',
      roles: ['GetBanks']
    },
    resolve: {
      banks : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('banks', $stateParams.id);
      }]
    }
  })
  .state('banks.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/banks/banks.edit.html',
        controller: 'BankCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutBanks']
    }
  })

  //#CREDITCARDTYPES
  .state('creditcardtypes', {
    parent: 'site',
    abstract: true,
    url: '/creditcardtypes',
    templateUrl: 'views/masters/creditcardtypes/creditcardtypes.index.html',
    data: {
      breadcrumbProxy: 'creditcardtypes.list'
    }
  })
  .state('creditcardtypes.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/creditcardtypes/creditcardtypes.list.html',
        controller: 'CreditcardtypesCtrl'
      }
    },
    data: {
      displayName: 'Credit Card Types',
      roles: ['GetCreditCardTypes']
    }
  })
  .state('creditcardtypes.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/creditcardtypes/creditcardtypes.create.html',
        controller: 'CreditcardtypesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostCreditCardTypes']
    }
  })
  .state('creditcardtypes.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/creditcardtypes/creditcardtypes.show.html',
        controller: 'CreditcardtypeCtrl'
      }
    },
    data: {
      displayName: '{{ creditcardtypes.data.Name }}',
      roles: ['GetCreditCardTypes']
    },
    resolve: {
      creditcardtypes : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('credit_card_types', $stateParams.id);
      }]
    }
  })
  .state('creditcardtypes.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/creditcardtypes/creditcardtypes.edit.html',
        controller: 'CreditcardtypeCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutCreditCardTypes']
    }
  })

  //#BANKTRANSFERRECORDS
  .state('banktransferrecords', {
    parent: 'site',
    abstract: true,
    url: '/banktransferrecords',
    templateUrl: 'views/masters/banktransferrecords/banktransferrecords.index.html',
    data: {
      breadcrumbProxy: 'banktransferrecords.list'
    }
  })
  .state('banktransferrecords.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/banktransferrecords/banktransferrecords.list.html',
        controller: 'BanktransferrecordsCtrl'
      }
    },
    data: {
      displayName: 'Bank Transfer Records',
      roles: ['GetBankTransfers']
    }
  })
  .state('banktransferrecords.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/banktransferrecords/banktransferrecords.create.html',
        controller: 'BanktransferrecordsCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostBankTransfers']
    }
  })
  .state('banktransferrecords.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/banktransferrecords/banktransferrecords.show.html',
        controller: 'BanktransferrecordCtrl'
      }
    },
    data: {
      displayName: '{{ banktransferrecords.TimeClassLabel }}',
      roles: ['GetBankTransfers']
    },
    resolve: {
      banktransferrecords : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('bank_transfers', $stateParams.id);
      }]
    }
  })
  .state('banktransferrecords.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/banktransferrecords/banktransferrecords.edit.html',
        controller: 'BanktransferrecordCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutBankTransfers']
    }
  })

  //#CREDICARDTRANSACTIONRECORDS
  .state('creditcardtransactionrecords', {
    parent: 'site',
    abstract: true,
    url: '/creditcardtransactionrecords',
    templateUrl: 'views/masters/creditcardtransactionrecords/creditcardtransactionrecords.index.html',
    data: {
      breadcrumbProxy: 'creditcardtransactionrecords.list'
    }
  })
  .state('creditcardtransactionrecords.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/creditcardtransactionrecords/creditcardtransactionrecords.list.html',
        controller: 'CreditcardtransactionrecordsCtrl'
      }
    },
    data: {
      displayName: 'Credit Card Transaction Records',
      roles: ['GetCreditCardPayments']
    }
  })
  .state('creditcardtransactionrecords.fee', {
    url: '/fee',
    views: {
      'main': {
        templateUrl: 'views/masters/creditcardtransactionrecords/creditcardtransactionrecords.fee.html',
        controller: 'CreditcardtransactionrecordFeeCtrl'
      }
    },
    data: {
      displayName: 'Fee',
      roles: ['GetCreditCardPayments']
    }
  })
  .state('creditcardtransactionrecords.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/creditcardtransactionrecords/creditcardtransactionrecords.create.html',
        controller: 'CreditcardtransactionrecordsCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostCreditCardPayments']
    }
  })
  .state('creditcardtransactionrecords.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/creditcardtransactionrecords/creditcardtransactionrecords.show.html',
        controller: 'CreditcardtransactionrecordCtrl'
      }
    },
    data: {
      displayName: '{{ creditcardtransactionrecords.TimeClassLabel }}',
      roles: ['GetCreditCardPayments']
    },
    resolve: {
      creditcardtransactionrecords : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('creditcardtransactionrecords', $stateParams.id);
      }]
    }
  })
  .state('creditcardtransactionrecords.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/creditcardtransactionrecords/creditcardtransactionrecords.edit.html',
        controller: 'CreditcardtransactionrecordCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutCreditCardPayments']
    }
  })

  //#SUPPLIERS
  .state('suppliers', {
    parent: 'site',
    abstract: true,
    url: '/suppliers',
    templateUrl: 'views/masters/suppliers/suppliers.index.html',
    data: {
      breadcrumbProxy: 'suppliers.list'
    }
  })
  .state('suppliers.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/suppliers/suppliers.list.html',
        controller: 'SuppliersCtrl'
      }
    },
    data: {
      displayName: 'Suppliers',
      roles: ['GetSuppliers']
    }
  })
  .state('suppliers.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/suppliers/suppliers.create.html',
        controller: 'SuppliersCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostSuppliers']
    }
  })
  .state('suppliers.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/suppliers/suppliers.show.html',
        controller: 'SupplierCtrl'
      }
    },
    data: {
      displayName: '{{ suppliers.TimeClassLabel }}',
      roles: ['GetSuppliers']
    },
    resolve: {
      suppliers : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('suppliers', $stateParams.id);
      }]
    }
  })
  .state('suppliers.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/suppliers/suppliers.edit.html',
        controller: 'SupplierCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutSuppliers']
    }
  })

  //#INVENTORIES
  .state('inventories', {
    parent: 'site',
    abstract: true,
    url: '/inventories',
    templateUrl: 'views/masters/inventories/inventories.index.html',
    data: {
      breadcrumbProxy: 'inventories.list'
    }
  })
  .state('inventories.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/inventories/inventories.list.html',
        controller: 'InventoriesCtrl'
      }
    },
    data: {
      displayName: 'Inventories',
      roles: ['GetInventories']
    }
  })
  .state('inventories.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/inventories/inventories.create.html',
        controller: 'InventoriesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostInventories']
    }
  })
  .state('inventories.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/inventories/inventories.show.html',
        controller: 'InventoryCtrl'
      }
    },
    data: {
      displayName: '{{ inventories.TimeClassLabel }}',
      roles: ['GetInventories']
    },
    resolve: {
      inventories : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('inventories', $stateParams.id);
      }]
    }
  })
  .state('inventories.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/inventories/inventories.edit.html',
        controller: 'InventoryCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutInventories']
    }
  })

  //#PRODUCTCATEGORIES
  .state('productcategories', {
    parent: 'site',
    abstract: true,
    url: '/productcategories',
    templateUrl: 'views/masters/productcategories/productcategories.index.html',
    data: {
      breadcrumbProxy: 'productcategories.list'
    }
  })
  .state('productcategories.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/productcategories/productcategories.list.html',
        controller: 'ProductcategoriesCtrl'
      }
    },
    data: {
      displayName: 'Product Categories',
      roles: ['GetProductCategories']
    }
  })
  .state('productcategories.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/productcategories/productcategories.create.html',
        controller: 'ProductcategoriesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostProductCategories']
    }
  })
  .state('productcategories.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/productcategories/productcategories.show.html',
        controller: 'ProductcategoryCtrl'
      }
    },
    data: {
      displayName: '{{ productcategories.data.Name }}',
      roles: ['GetProductCategories']
    },
    resolve: {
      productcategories : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('product_categories', $stateParams.id);
      }]
    }
  })
  .state('productcategories.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/productcategories/productcategories.edit.html',
        controller: 'ProductcategoryCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutProductCategories']
    }
  })

  //#UNITS
  .state('units', {
    parent: 'site',
    abstract: true,
    url: '/units',
    templateUrl: 'views/masters/units/units.index.html',
    data: {
      breadcrumbProxy: 'units.list'
    }
  })
  .state('units.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/units/units.list.html',
        controller: 'UnitsCtrl'
      }
    },
    data: {
      displayName: 'Units',
      roles: ['GetUnits']
    }
  })
  .state('units.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/units/units.create.html',
        controller: 'UnitsCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostUnits']
    }
  })
  .state('units.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/units/units.show.html',
        controller: 'UnitCtrl'
      }
    },
    data: {
      displayName: '{{ units.data.Name }}',
      roles: ['GetUnits']
    },
    resolve: {
      units : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('units', $stateParams.id);
      }]
    }
  })
  .state('units.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/units/units.edit.html',
        controller: 'UnitCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutUnits']
    }
  })

  //#PRODUCTS
  .state('products', {
    parent: 'site',
    abstract: true,
    url: '/products',
    templateUrl: 'views/masters/products/products.index.html',
    data: {
      breadcrumbProxy: 'products.list'
    }
  })
  .state('products.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/products/products.list.html',
        controller: 'ProductsCtrl'
      }
    },
    data: {
      displayName: 'Products',
      roles: ['GetProduct']
    }
  })
  .state('products.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/products/products.create.html',
        controller: 'ProductsCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostProduct']
    }
  })
  .state('products.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/products/products.show.html',
        controller: 'ProductCtrl'
      }
    },
    data: {
      displayName: '{{ products.TimeClassLabel }}',
      roles: ['GetProduct']
    },
    resolve: {
      products : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('products', $stateParams.id);
      }]
    }
  })
  .state('products.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/products/products.edit.html',
        controller: 'ProductCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutProduct']
    }
  })

  //#CLIENTS
  .state('clients', {
    parent: 'site',
    abstract: true,
    url: '/clients',
    templateUrl: 'views/masters/clients/clients.index.html',
    data: {
      breadcrumbProxy: 'clients.list'
    }
  })
  .state('clients.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/clients/clients.list.html',
        controller: 'ClientsCtrl'
      }
    },
    data: {
      displayName: 'Clients',
      roles: ['GetClients']
    }
  })
  .state('clients.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/clients/clients.create.html',
        controller: 'ClientCreateCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostClients']
    }
  })
  .state('clients.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/clients/clients.show.html',
        controller: 'SupplierCtrl'
      }
    },
    data: {
      displayName: '{{ client.Name }}',
      roles: ['GetClients']
    },
    resolve: {
      client : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('clients', $stateParams.id);
      }]
    }
  })
  .state('clients.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/masters/clients/clients.edit.html',
        controller: 'ClientCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutClients']
    }
  })
  // ================MASTER============ #END



  // ================TRANSACTIONAL============ #START
  //#COURSES
  .state('courses', {
    parent: 'site',
    abstract: true,
    url: '/courses',
    templateUrl: 'views/modules/courses/courses.index.html',
    data: {
      breadcrumbProxy: 'courses.list'
    }
  })
  .state('courses.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/modules/courses/courses.list.html',
        controller: 'CoursesCtrl'
      }
    },
    data: {
      displayName: 'Courses',
      roles: ['GetCourses']
    }
  })
  .state('courses.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/modules/courses/courses.create.html',
        controller: 'CoursesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostCourses']
    }
  })
  .state('courses.fee', {
    url: '/fee',
    views: {
      'main': {
        templateUrl: 'views/modules/courses/courses.fee.html',
        controller: 'CourseFeeCtrl'
      }
    },
    data: {
      displayName: 'Fee',
      roles: ['GetCourses']
    }
  })
  .state('courses.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/courses/courses.show.html',
        controller: 'CourseCtrl'
      }
    },
    data: {
      displayName: '{{ course.CourseName }}',
      roles: ['GetCourses']
    },
    resolve: {
      course : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem($stateParams.id);
      }]
    }
  })
  .state('courses.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/modules/courses/courses.edit.html',
        controller: 'CourseCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutCourses']
    }
  })
  .state('courses.installment', {
    url: '/:id/installment',
    views: {
      'main': {
        templateUrl: 'views/modules/courses/courses.installment.html',
        controller: 'CourseInstallmentCtrl'
      }
    },
    data: {
      displayName: 'installment',
      roles: ['GetCourses']
    }
  })


  //#COURSES SCHEDULE
  .state('courseSchedules', {
    parent: 'site',
    abstract: true,
    url: '/courseschedules',
    templateUrl: 'views/modules/course-schedules/course.schedules.index.html',
    data: {
      breadcrumbProxy: 'courseSchedules.list'
    }
  })
  .state('courseSchedules.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/modules/course-schedules/course.schedules.list.html',
        controller: 'CourseSchedulesCtrl'
      }
    },
    data: {
      displayName: 'Course Schedules',
      roles: ['GetCourseSchedules']
    }
  })
  .state('courseSchedules.info', {
    url: '/class_list/:id/info',
    views: {
      'main': {
        templateUrl: 'views/modules/course-schedules/class.info.html',
        controller: 'ClassInfoCtrl'
      }
    },
    data: {
      displayName: 'Info',
      roles: ['GetCourseSchedules']
    }
  })
  .state('courseSchedules.student_ids', {
    url: '/class_list/:id/student_ids',
    views: {
      'main': {
        templateUrl: 'views/modules/course-schedules/class.ids.html',
        controller: 'ClassIdsCtrl'
      }
    },
    data: {
      displayName: 'Student Ids',
      roles: ['GetCourseSchedules']
    }
  })
  .state('courseSchedules.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/modules/course-schedules/course.schedules.create.html',
        controller: 'CourseSchedulesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostCourseSchedules']
    }
  })
  .state('courseSchedules.edit', {
    url: '/:id/edit',
    views: {
      'main': {
        templateUrl: 'views/modules/course-schedules/course.schedules.edit.html',
        controller: 'CourseScheduleCtrl'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['EditCourseSchedules']
    }
  })
  .state('courseSchedules.teachers', {
    url: '/:id/teachers',
    views: {
      'main': {
        templateUrl: 'views/modules/course-schedules/course.schedules.teachers.html',
        controller: 'CourseScheduleTeachersCtrl'
      }
    },
    data: {
      displayName: 'teachers',
      roles: ['GetCourseSchedules']
    }
  })
  .state('courseSchedules.activities', {
    url: '/:id/activities',
    views: {
      'main': {
        templateUrl: 'views/modules/course-schedules/course.schedules.activities.html',
        controller: 'CourseScheduleActivitiesCtrl'
      }
    },
    data: {
      displayName: 'activities',
      roles: ['GetCourseSchedules']
    }
  })

  // #CLASS LIST
  .state('classes', {
    parent: 'site',
    abstract: true,
    url: '/classes',
    templateUrl: 'views/modules/course-schedules/course.schedules.index.html',
    data: {
      breadcrumbProxy: 'clasess.list'
    }
  })
  .state('classes.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/modules/course-schedules/class.list.html',
        controller: 'ClassListsCtrl'
      }
    },
    data: {
      displayName: 'Class List',
      roles: ['GetCourseSchedules']
    }
  })
  .state('classes.searchList', {
    url: '/search/:course/:term',
    views: {
      'main': {
        templateUrl: 'views/modules/course-schedules/class.list.html',
        controller: 'ClassListsCtrl'
      }
    },
    data: {
      displayName: 'Class List',
      roles: ['GetCourseSchedules']
    }
  })
  .state('classes.raffled', {
    url: '/raffled',
    views: {
      'main': {
        templateUrl: 'views/modules/course-schedules/class.raffled.html',
        controller: 'RaffledCtrl'
      }
    },
    data: {
      displayName: 'Student Raffled',
      roles: ['GetCourseSchedules']
    }
  })
  .state('classes.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/course-schedules/course.schedules.show.html',
        controller: 'CourseCtrl'
      }
    },
    data: {
      displayName: '{{ courseschedule.data.Course.CourseLevel.Name }}/{{ courseschedule.data.Course.CourseLevel.Code }}/{{ courseschedule.data.Suffix }}',
      roles: ['GetCourseSchedules']
    },
    resolve: {
      courseschedule : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('course_schedules', $stateParams.id);
      }]
    }
  })
  .state('classes.show.assessment', {
    url: '/assessment',
    views: {
      'sub': {
        templateUrl: 'views/modules/course-schedules/class.assessment.html',
        controller: 'ClassAssessmentCtrl'
      }
    },
    data: {
      displayName: 'Assessment',
      roles: ['GetEnrollments', 'GetCourseSchedules']
    }
  })
  .state('classes.show.report', {
    url: '/report',
    views: {
      'sub': {
        templateUrl: 'views/reports/report.class.html',
        controller: 'ClassReportCtrl'
      }
    },
    data: {
      displayName: 'Report',
      roles: ['GetUser']
    }
  })

  //#PLACEMENT TEST
  .state('pt', {
    parent: 'site',
    abstract: true,
    url: '/placementtest',
    templateUrl: 'views/modules/pt/pt.index.html',
    data: {
      breadcrumbProxy: 'pt.list'
    }
  })
  .state('pt.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/modules/pt/pt.list.html',
        controller: 'PlacementTestCtrl'
      }
    },
    data: {
      displayName: 'Placement Test',
      roles: ['GetPlacementTests']
    }
  })
  .state('pt.searchList', {
    url: '/new/search/:key',
    views: {
      'main': {
        templateUrl: 'views/modules/pt/pt.create.html',
        controller: 'PlacementTestCreateCtrl'
      }
    },
    data: {
      displayName: 'Placement Test',
      roles: ['GetPlacementTests']
    }
  })
  .state('pt.new', {
    url: '/new/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/pt/pt.create.html',
        controller: 'PlacementTestCreateCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostPlacementTests']
    }
  })
  .state('pt.fee', {
    url: '/fee',
    views: {
      'main': {
        templateUrl: 'views/modules/pt/pt.fee.html',
        controller: 'PlacementTestFeeCtrl'
      }
    },
    data: {
      displayName: 'Fee',
      roles: ['GetPlacementTests']
    }
  })
  .state('pt.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/pt/pt.show.html',
        controller: 'PTsingleCtrl'
      }
    },
    data: {
      displayName: '{{ pt.data.Student.FullName }} - {{ pt.data.DateTime | date: medium }}',
      roles: ['GetPlacementTests']
    },
    resolve: {
      pt : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('placement_tests', $stateParams.id);
      }]
    }
  })
  .state('pt.show.edit', {
    url: '/edit',
    views: {
      'sub': {
        templateUrl: 'views/modules/pt/pt.edit.html'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['GetPlacementTests']
    }
  })

  //#MAKE UP TEST
  .state('mt', {
    parent: 'site',
    abstract: true,
    url: '/makeuptest',
    templateUrl: 'views/modules/mt/mt.index.html',
    data: {
      breadcrumbProxy: 'mt.list'
    }
  })
  .state('mt.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/modules/mt/mt.list.html',
        controller: 'MakeupTestCtrl'
      }
    },
    data: {
      displayName: 'Make Up Test',
      roles: ['GetMakeUpTests']
    }
  })
  .state('mt.schedules', {
    url: '/schedules',
    views: {
      'main': {
        templateUrl: 'views/modules/mt/mt.schedule.html',
        controller: 'MakeupTestSchedulesCtrl'
      }
    },
    data: {
      displayName: 'Schedules',
      roles: ['GetMakeUpTestSchedules']
    }
  })
  .state('mt.schedulenew', {
    url: '/schedules/new',
    views: {
      'main': {
        templateUrl: 'views/modules/mt/mt.schedule.new.html',
        controller: 'MakeupTestSchedulesCtrl'
      }
    },
    data: {
      displayName: 'New Schedule (Single)',
      roles: ['PostMakeUpTestSchedules']
    }
  })
  .state('mt.schedulenewbatch', {
    url: '/schedules/new_batch',
    views: {
      'main': {
        templateUrl: 'views/modules/mt/mt.schedule.new_batch.html',
        controller: 'MakeupTestSchedulesBatchCtrl'
      }
    },
    data: {
      displayName: 'New Schedule (Batch)',
      roles: ['PostMakeUpTestSchedules']
    }
  })
  .state('mt.scheduleedit', {
    url: '/schedules/edit/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/mt/mt.schedule.edit.html',
        controller: 'MakeupTestScheduleCtrl'
      }
    },
    data: {
      displayName: 'Edit',
      roles: ['PutMakeUpTestSchedules']
    }
  })
  .state('mt.fee', {
    url: '/fee',
    views: {
      'main': {
        templateUrl: 'views/modules/mt/mt.fee.html',
        controller: 'MakeupTestFeeCtrl'
      }
    },
    data: {
      displayName: 'Fee',
      roles: ['GetMakeUpTestFees']
    }
  })
  .state('mt.new', {
    url: '/new/{id}',
    views: {
      'main': {
        templateUrl: 'views/modules/mt/mt.create.html',
        controller: 'MakeupTestCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostMakeUpTests']
    }
  })
  .state('mt.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/mt/mt.show.html',
        controller: 'MTsingleCtrl'
      }
    },
    data: {
      displayName: '{{ course.CourseName }}',
      roles: ['GetMakeUpTests']
    },
    resolve: {
      course : ['$stateParams', 'Courses', function($stateParams, Courses) {
        return Courses.getCourse($stateParams.id);
      }]
    }
  })
  .state('mt.show.edit', {
    url: '/edit',
    views: {
      'sub': {
        templateUrl: 'views/modules/mt/mt.edit.html',
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutMakeUpTests']
    }
  })

  //#ENROLLMENT
  .state('sr', {
    parent: 'site',
    abstract: true,
    url: '/studentregistration',
    templateUrl: 'views/modules/sr/sr.index.html',
    data: {
      breadcrumbProxy: 'sr.list'
    }
  })
  .state('sr.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/modules/sr/sr.create.html',
        controller: 'StudentRegistrationCtrl'
      }
    },
    data: {
      displayName: 'Enrollment',
      roles: ['GetEnrollments']
    }
  })
  .state('sr.searchList', {
    url: '/new/search/:key',
    views: {
      'main': {
        templateUrl: 'views/modules/sr/sr.create.html',
        controller: 'StudentRegistrationCreateCtrl'
      }
    },
    data: {
      displayName: 'Enrollment',
      roles: ['GetEnrollments']
    }
  })
  .state('sr.new', {
    url: '/new/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/sr/sr.create.html',
        controller: 'StudentRegistrationCreateCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostEnrollments']
    }
  })

  //#PAYMENTS
  .state('payments', {
    parent: 'site',
    abstract: true,
    url: '/payments',
    templateUrl: 'views/modules/payment/payment.index.html',
    data: {
      breadcrumbProxy: 'payments.list'
    }
  })
  .state('payments.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/modules/payment/payment.list.html',
        controller: 'PaymentsCtrl'
      }
    },
    data: {
      displayName: 'Payments',
      roles: ['GetPayments']
    }
  })
  .state('payments.new', {
    url: '/new/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/payment/payment.create.html',
        controller: 'PaymentNewCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostPayments']
    }
  })
  .state('payments.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/payment/payment.show.html',
        controller: 'PaymentSingleCtrl'
      }
    },
    data: {
      displayName: '{{ payment.data.TransactionNumber }}',
      roles: ['GetPayments']
    },
    resolve: {
      payment : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('payments', $stateParams.id);
      }]
    }
  })
  .state('payments.show.print', {
    url: '/print',
    views: {
      'sub': {
        templateUrl: 'views/modules/payment/payment.print.html'
      }
    },
    data: {
      displayName: 'print',
      roles: ['GetPayments']
    }
  })
  .state('payments.show.edit', {
    url: '/edit',
    views: {
      'sub': {
        templateUrl: 'views/modules/payment/payment.edit.html'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutPayments']
    }
  })

  //#INVOICES
  .state('invoices', {
    parent: 'site',
    abstract: true,
    url: '/pending_payments',
    templateUrl: 'views/modules/invoice/invoice.index.html',
    data: {
      breadcrumbProxy: 'invoices.list'
    }
  })
  .state('invoices.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/modules/invoice/invoice.list.html',
        controller: 'InvoicesCtrl'
      }
    },
    data: {
      displayName: 'Payments',
      roles: ['GetInvoices']
    }
  })
  .state('invoices.new', {
    url: '/new/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/invoice/invoice.create.html',
        controller: 'InvoiceNewCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostInvoices']
    }
  })

  //#REFUND TYPES
  .state('refundtypes', {
    parent: 'site',
    abstract: true,
    url: '/refundtypes',
    templateUrl: 'views/masters/refund-types/refund-types.index.html',
    data: {
      breadcrumbProxy: 'refund-types.list'
    }
  })
  .state('refundtypes.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/refund-types/refund-types.list.html',
        controller: 'RefundTypesCtrl'
      }
    },
    data: {
      displayName: 'Refund Types',
      roles: ['GetRefundTypes']
    }
  })
  .state('refundtypes.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/refund-types/refund-types.create.html',
        controller: 'RefundTypesCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostRefundTypes']
    }
  })
  .state('refundtypes.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/refund-types/refund-types.show.html',
        controller: 'RefundTypeCtrl'
      }
    },
    data: {
      displayName: '{{ item.data.Name }}',
      roles: ['GetRefundTypes']
    },
    resolve: {
      item : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('refund_types', $stateParams.id);
      }]
      }
  })
  .state('refundtypes.show.edit', {
    url: '/edit',
    views: {
      'sub': {
        templateUrl: 'views/masters/refund-types/refund-types.edit.html'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutRefundTypes']
    }
  })

  //#REFUND
  .state('refund', {
    parent: 'site',
    abstract: true,
    url: '/refunds',
    templateUrl: 'views/modules/refund/refund.index.html',
    data: {
      breadcrumbProxy: 'refund.list'
    }
  })
  .state('refund.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/modules/refund/refund.list.html',
        controller: 'RefundsCtrl'
      }
    },
    data: {
      displayName: 'Refund',
      roles: ['GetRefunds']
    }
  })
  .state('refund.new', {
    url: '/new/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/refund/refund.create.html',
        controller: 'RefundCreateCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['GetRefunds']
    }
  })
  .state('refund.move', {
    url: '/move/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/refund/refund.move.html',
        controller: 'RefundMoveCtrl'
      }
    },
    data: {
      displayName: 'Move',
      roles: ['GetRefunds', 'PutEnrollments', 'PostEnrollments']
    }
  })
  .state('refund.cancel', {
    url: '/cancel/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/refund/refund.cancel.html',
        controller: 'RefundCancelCtrl'
      }
    },
    data: {
      displayName: 'Cancel',
      roles: ['GetRefunds', 'PutEnrollments']
    }
  })
  .state('refund.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/modules/refund/refund.show.html',
        controller: 'RefundCtrl'
      }
    },
    data: {
      displayName: '{{ refund.data.Amount }}',
      roles: ['GetRefunds']
    },
    resolve: {
      refund : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('refunds', $stateParams.id);
      }]
    }
  })
  .state('refund.show.edit', {
    url: '/edit',
    views: {
      'sub': {
        templateUrl: 'views/modules/refund/refund.edit.html'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutRefunds']
    }
  })

  //#DISCOUNT TYPES
  .state('discount_types', {
    parent: 'site',
    abstract: true,
    url: '/discount_types',
    templateUrl: 'views/masters/discount_types/discount_types.index.html',
    data: {
      breadcrumbProxy: 'discount_types.list'
    }
  })
  .state('discount_types.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/discount_types/discount_types.list.html',
        controller: 'DiscountTypesCtrl'
      }
    },
    data: {
      displayName: 'Discount Types',
      roles: ['GetDiscountTypes']
    }
  })
  .state('discount_types.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/discount_types/discount_types.create.html',
        controller: 'DiscountTypeCreateCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostDiscountTypes']
    }
  })
  .state('discount_types.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/discount_types/discount_types.show.html',
        controller: 'DiscountTypeCtrl'
      }
    },
    data: {
      displayName: '{{ item.data.Name }}',
      roles: ['GetDiscountTypes']
    },
    resolve: {
      item : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('discount_types', $stateParams.id);
      }]
      }
  })
  .state('discount_types.show.edit', {
    url: '/edit',
    views: {
      'sub': {
        templateUrl: 'views/masters/discount_types/discount_types.edit.html'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutDiscountTypes']
    }
  })

  //#ROLE PROFILES
  .state('role_profiles', {
    parent: 'site',
    abstract: true,
    url: '/role_profiles',
    templateUrl: 'views/masters/role_profiles/role_profiles.index.html',
    data: {
      breadcrumbProxy: 'role_profiles.list'
    }
  })
  .state('role_profiles.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/role_profiles/role_profiles.list.html',
        controller: 'RoleProfilesCtrl'
      }
    },
    data: {
      displayName: 'Roles',
      roles: ['GetRoleProfiles']
    }
  })
  .state('role_profiles.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/role_profiles/role_profiles.create.html',
        controller: 'RoleProfileCreateCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostRoleProfiles']
    }
  })
  .state('role_profiles.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/role_profiles/role_profiles.show.html',
        controller: 'RoleProfileCtrl'
      }
    },
    data: {
      displayName: '{{ item.data.Name }}',
      roles: ['GetRoleProfiles']
    },
    resolve: {
      item : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('role_profiles', $stateParams.id);
      }]
      }
  })
  .state('role_profiles.show.edit', {
    url: '/edit',
    views: {
      'sub': {
        templateUrl: 'views/masters/role_profiles/role_profiles.edit.html'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutRoleProfiles']
    }
  })

  //#STUDENT DISCOUNTS
  .state('student_discounts', {
    parent: 'site',
    abstract: true,
    url: '/student_discounts',
    templateUrl: 'views/masters/student_discounts/student_discounts.index.html',
    data: {
      breadcrumbProxy: 'student_discounts.list'
    }
  })
  .state('student_discounts.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/student_discounts/student_discounts.list.html',
        controller: 'StudentDiscountsCtrl'
      }
    },
    data: {
      displayName: 'Student Discounts',
      roles: ['GetStudentDiscounts']
    }
  })
  .state('student_discounts.searchList', {
    url: '/new/search/:key',
    views: {
      'main': {
        templateUrl: 'views/masters/student_discounts/student_discounts.create.html',
        controller: 'StudentDiscountCreateCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['GetStudentDiscounts']
    }
  })
  .state('student_discounts.new', {
    url: '/new/{id}',
    views: {
      'main': {
        templateUrl: 'views/masters/student_discounts/student_discounts.create.html',
        controller: 'StudentDiscountCreateCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostStudentDiscounts']
    }
  })
  .state('student_discounts.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/student_discounts/student_discounts.show.html',
        controller: 'StudentDiscountCtrl'
      }
    },
    data: {
      displayName: '{{ item.data.Id }}',
      roles: ['GetStudentDiscounts']
    },
    resolve: {
      item : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('student_discounts', $stateParams.id);
      }]
      }
  })
  .state('student_discounts.show.edit', {
    url: '/edit',
    views: {
      'sub': {
        templateUrl: 'views/masters/student_discounts/student_discounts.edit.html'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutStudentDiscounts']
    }
  })

  //#STOCKS
  .state('stocks', {
    parent: 'site',
    abstract: true,
    url: '/stocks',
    templateUrl: 'views/masters/stocks/stocks.index.html',
    data: {
      breadcrumbProxy: 'stocks.list'
    }
  })
  .state('stocks.list', {
    url: '',
    views: {
      'main': {
        templateUrl: 'views/masters/stocks/stocks.list.html',
        controller: 'StocksCtrl'
      }
    },
    data: {
      displayName: 'Stocks',
      roles: ['GetStocks']
    }
  })
  .state('stocks.new', {
    url: '/new',
    views: {
      'main': {
        templateUrl: 'views/masters/stocks/stocks.create.html',
        controller: 'StockCreateCtrl'
      }
    },
    data: {
      displayName: 'New',
      roles: ['PostStocks', 'PutStocks']
    }
  })
  .state('stocks.new.in', {
    url: '/stock_in',
    views: {
      'sub': {
        templateUrl: 'views/masters/stocks/stocks.create.in.html',
        controller: 'StockCreateInCtrl'
      }
    },
    data: {
      displayName: 'Stock In',
      roles: ['PostStocks', 'PutStocks']
    }
  })
  .state('stocks.new.out', {
    url: '/stock_out',
    views: {
      'sub': {
        templateUrl: 'views/masters/stocks/stocks.create.out.html',
        controller: 'StockCreateOutCtrl'
      }
    },
    data: {
      displayName: 'Stock Out',
      roles: ['PutStocks']
    }
  })
  .state('stocks.new.transfer', {
    url: '/stock_transfer',
    views: {
      'sub': {
        templateUrl: 'views/masters/stocks/stocks.create.transfer.html',
        controller: 'StockCreateTransferCtrl'
      }
    },
    data: {
      displayName: 'Stock Transfer',
      roles: ['PutStocks', 'PostStocks']
    }
  })
  .state('stocks.show', {
    url: '/:id',
    views: {
      'main': {
        templateUrl: 'views/masters/stocks/stocks.show.html',
        controller: 'StockCtrl'
      }
    },
    data: {
      displayName: '{{ item.data.Name }}',
      roles: ['GetStocks']
    },
    resolve: {
      item : ['$stateParams', 'Services', function($stateParams, Services) {
        return Services.getItem('stocks', $stateParams.id);
      }]
      }
  })
  .state('stocks.show.edit', {
    url: '/edit',
    views: {
      'sub': {
        templateUrl: 'views/masters/stocks/stocks.edit.html'
      }
    },
    data: {
      displayName: 'edit',
      roles: ['PutStocks']
    }
  })
  // ================TRANSACTIONAL============ #END


  // ================TRANSACTIONAL============ #START
  .state('reports', {
    parent: 'site',
    url: '/reports',
    templateUrl: 'views/reports/index.html'
  })
  .state('reports.term_target', {
    url: '/term_target',
    views: {
      'main': {
        templateUrl: 'views/reports/term.target.html',
        controller: 'TermTargetCtrl'
      }
    },
    data: {
      displayName: 'Term Target',
      roles: ['GetRegistrationFigures']
    }
  })
  .state('reports.ge_class', {
    url: '/ge_class_report',
    views: {
      'main': {
        templateUrl: 'views/reports/ge.class.html',
        controller: 'GeClassReportCtrl'
      }
    },
    data: {
      displayName: 'GE Class Report',
      roles: ['GetRegistrationFigures']
    }
  })
  .state('reports.ge_student', {
    url: '/ge_student_report',
    views: {
      'main': {
        templateUrl: 'views/reports/ge.student.html',
        controller: 'GeStudentReportCtrl'
      }
    },
    data: {
      displayName: 'GE Student List Report',
      roles: ['GetRegistrationFigures']
    }
  })
  .state('reports.fo_pt', {
    url: '/fo_pt_report',
    views: {
      'main': {
        templateUrl: 'views/reports/fo.pt.html',
        controller: 'FoPtReportCtrl'
      }
    },
    data: {
      displayName: 'FO Placement Test Report',
      roles: ['GetRegistrationFigures']
    }
  })
  .state('reports.cashier_daily', {
    url: '/cashier_daily_report',
    views: {
      'main': {
        templateUrl: 'views/reports/cashier.daily.html',
        controller: 'CashierDailyReportCtrl'
      }
    },
    data: {
      displayName: 'Cashier Daily Sales Report',
      roles: ['GetRegistrationFigures']
    }
  })
  .state('reports.finance_refund', {
    url: '/finance_refund_report',
    views: {
      'main': {
        templateUrl: 'views/reports/finance.refund.html',
        controller: 'FinanceRefundReportCtrl'
      }
    },
    data: {
      displayName: 'Finance Refund Settlement Report',
      roles: ['GetRegistrationFigures']
    }
  })
  .state('reports.finance_fee', {
    url: '/finance_fee_report',
    views: {
      'main': {
        templateUrl: 'views/reports/finance.fee.html',
        controller: 'FinanceFeeReportCtrl'
      }
    },
    data: {
      displayName: 'Finance Course Fee Class Report',
      roles: ['GetRegistrationFigures']
    }
  })
  .state('reports.finance_summary', {
    url: '/finance_summary_report',
    views: {
      'main': {
        templateUrl: 'views/reports/finance.summary.html',
        controller: 'FinanceSummaryReportCtrl'
      }
    },
    data: {
      displayName: 'Finance Summary Course Report',
      roles: ['GetRegistrationFigures']
    }
  })
  .state('reports.finance_income', {
    url: '/finance_income_report',
    views: {
      'main': {
        templateUrl: 'views/reports/finance.income.html',
        controller: 'FinanceIncomeReportCtrl'
      }
    },
    data: {
      displayName: 'Finance Income Report',
      roles: ['GetRegistrationFigures']
    }
  })
  .state('reports.finance_payment', {
    url: '/finance_payment_report',
    views: {
      'main': {
        templateUrl: 'views/reports/finance.payment.html',
        controller: 'FinancePaymentReportCtrl'
      }
    },
    data: {
      displayName: 'Finance Student Payment Report',
      roles: ['GetRegistrationFigures']
    }
  })
  // ================TRANSACTIONAL============ #END


  ;

  // $locationProvider.html5Mode(true);
}])
.run(['$rootScope', '$state', '$stateParams', 'authorization', 'principal', '$timeout', '$filter', '_', 'Services', 'ServicesLS', function($rootScope, $state, $stateParams, authorization, principal, $timeout, $filter, _, Services, ServicesLS) {

    $rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) {
      // console.log("changed");
      $rootScope.toState = toState;
      $rootScope.toStateParams = toStateParams;

      // console.log(principal.isIdentityResolved());

      if (principal.isIdentityResolved()){
        authorization.authorize();
      }
    });

    $rootScope.loggedInUser = {};
    var name = ServicesLS.get('_name');
    $rootScope.loggedInUser.Username = name;

    $rootScope.AmountTypes = [
      {
        'Label': 'Nominal',
        'Id': 0,
        'Sign': ''
      },
      {
        'Label': 'Percentage',
        'Id': 1,
        'Sign': '%'
      }
    ];

    $rootScope.ScoreTypes = [
      {
        'Label': 'Range',
        'Id': 0
      },
      {
        'Label': 'Look Up',
        'Id': 1
      }
    ];

    $rootScope.Sexes = [
      {
        'Label': 'Male',
        'Id': 0,
        'Icon': 'icon-symbol-male'
      },
      {
        'Label': 'Female',
        'Id': 1,
        'Icon': 'icon-symbol-female'
      }
    ];

    $rootScope.PaymentStatus = [
      {
        'Label'     : 'Invoice',
        'ExtraLabel': 'Pending',
        'Id': 0
      },
      {
        'Label'     : 'Receipt',
        'ExtraLabel': 'Paid',
        'Id': 1
      },
      {
        'Label'     : 'Postpone',
        'ExtraLabel': 'Pending',
        'Id': 2
      }
    ];

    $rootScope.PaymentMethods = [
      {
        'Label': 'Cash',
        'Id': 0
      },
      {
        'Label': 'Foreign Cash',
        'Id': 1
      },
      {
        'Label': 'Credit Card',
        'Id': 2
      },
      {
        'Label': 'Bank Transfer',
        'Id': 3
      }
    ];

    $rootScope.InvoiceTypes = [
      {
        'Label': 'Placement Test',
        'Query': 'placement_test',
        'Id': 0
      },
      {
        'Label': 'Enrollment',
        'Query': 'enrollment',
        'Id': 1
      },
      {
        'Label': 'Make Up Test',
        'Query': 'make_up_test',
        'Id': 2
      },
      {
        'Label': 'Refund',
        'Query': 'cancel_class,move_class',
        'Id': 3
      }
      // {
      //   'Label': 'Cancel Class',
      //   'Query': 'cancel_class',
      //   'Id': 3
      // },
      // {
      //   'Label': 'Move Class',
      //   'Query': 'move_class',
      //   'Id': 4
      // }
    ];

    $rootScope.TeacherTypes = [
      {
        Id: 0,
        Code: 'NAT',
        Name: 'Native'
      },
      {
        Id: 1,
        Code: 'IND',
        Name: 'Indonesian'
      },
      {
        Id: 2,
        Code: 'COM',
        Name: 'Combination'
      }
    ];

    $rootScope.StaffTypes = [
      {
        Id: 0,
        Name: 'Staff',
        Query: 'staff'
      },
      {
        Id: 1,
        Name: 'Indonesian Teacher',
        Query: 'teacher'
      },
      {
        Id: 2,
        Name: 'Native Teacher',
        Query: 'native_teacher'
      }
    ];

    $rootScope.StaffTeacherTypes = [
      {
        Id: 1,
        Name: 'Indonesian Teacher',
        Query: 'teacher'
      },
      {
        Id: 2,
        Name: 'Native Teacher',
        Query: 'native_teacher'
      }
    ];

    $rootScope.TeacherStaffTypes = [
      {
        Id: 0,
        Name: 'Native Teacher',
        Query: 'native_teacher'
      },
      {
        Id: 1,
        Name: 'Indonesian Teacher',
        Query: 'teacher'
      },
      {
        Id: 2,
        Name: 'Combination Teacher',
        Query: 'teacher,native_teacher'
      }
    ];

    $rootScope.CourseCompletionStatus = [
      {
        Id: 0,
        Label: 'Uncomplete',
        LabelClass: 'label-info'
      },
      {
        Id: 1,
        Label: 'High Pass',
        LabelClass: 'label-success'
      },
      {
        Id: 2,
        Label: 'Pass',
        LabelClass: 'label-success'
      },
      {
        Id: 3,
        Label: 'Borderline Pass',
        LabelClass: 'label-success'
      },
      {
        Id: 4,
        Label: 'Repeat',
        LabelClass: 'label-warning'
      },
      {
        Id: 5,
        Label: 'Free Repeat',
        LabelClass: 'label-warning'
      },
      {
        Id: 6,
        Label: 'Canceled',
        LabelClass: 'label-default'
      },
      {
        Id: 7,
        Label: 'Drop Out',
        LabelClass: 'label-danger'
      },
      {
        Id: 8,
        Label: 'Move Class',
        LabelClass: 'label-warning'
      },
      {
        Id: 9,
        Label: 'Make Up Test',
        LabelClass: 'label-warning'
      }
    ];

    $rootScope.MakeUpTestStatus = [
      {
        Id: 0,
        Label: 'Taken'
      },
      {
        Id: 1,
        Label: 'Cancelled'
      },
      {
        Id: 2,
        Label: 'Postponed'
      },
      {
        Id: 3,
        Label: 'Registered'
      }
    ];

    $rootScope.PlacementTestTypes = [
      {
        Id: 0,
        Label: 'Online'
      },
      {
        Id: 1,
        Label: 'Offline'
      }
    ];

    $rootScope.DiscountSourceTypes = [
      {
        Id: 0,
        Label: 'Enrollments'
      },
      {
        Id: 1,
        Label: 'Staffs'
      },
      {
        Id: 2,
        Label: 'Clients'
      },
      {
        Id: 3,
        Label: 'Others'
      }
    ];

    $rootScope.MakeUpTestTypes = [
      {
        Id: 0,
        Label: 'Final'
      },
      {
        Id: 1,
        Label: 'Speaking'
      }
    ];

    $rootScope.ScheduleTypes = [
      {
        Id: 0,
        Label: 'Regular'
      },
      {
        Id: 1,
        Label: 'New'
      }
    ];

    $rootScope.RefundStatus = [
      {
        Id: 0,
        Label: 'Requested'
      },
      {
        Id: 1,
        Label: 'Approved'
      },
      {
        Id: 2,
        Label: 'Paid'
      },
      {
        Id: 3,
        Label: 'Cancelled'
      },
      {
        Id: 4,
        Label: 'Cancelled'
      },
      {
        Id: 5,
        Label: 'Cancelled'
      },
      {
        Id: 6,
        Label: 'Re-Bank'
      }
    ];

    $rootScope.StockTransactionTypes = [
      {
        Id: 0,
        Label: 'Student Purchase'
      },
      {
        Id: 1,
        Label: 'Staff Purchase'
      },
      {
        Id: 2,
        Label: 'Inventory Transfer'
      },
      {
        Id: 3,
        Label: 'Stock Adjustment'
      },
      {
        Id: 4,
        Label: 'Supplier Return'
      },
      {
        Id: 5,
        Label: 'Request Order'
      }
    ];

    $rootScope.getProperty = function(query, array, target) {
      var result = _.findWhere(array, query);
      return result[target];
    };

    /********************
    * DATEPICKER START *
    ********************/
    $rootScope.datePicker = {
      'isOpen': []
    };

    $rootScope.openDatepicker = function($event, index) {
      $event.preventDefault();
      $event.stopPropagation();
      $timeout(function() {
        $rootScope.datePicker.isOpen[index] = true;
      }, 50);
    };

    $rootScope.responseError = {};

    $rootScope.dateOptions = {
      formatYear : 'yyyy',
      startingDay: 1
    };

    $rootScope.initDate = new Date();
    $rootScope.format = 'yyyy-MM-dd HH:mm:ss';

    /********************
    * DATEPICKER END *
    ********************/

    /********************
    * TIMEPICKER START *
    ********************/

    var timeTemp = new Date();
    timeTemp.setMinutes(0);
    timeTemp.setSeconds(0);
    // timeTemp = new Date( timeTemp.getTime() + ( timeTemp.getTimezoneOffset() * 60000 ) );
    console.log(timeTemp);

    $rootScope.timepicker = {
      timeA     : timeTemp,
      timeB     : timeTemp,
      hstep     : 1,
      mstep     : 5,
      isMeridian: true
    };

    /********************
    * TIMEPICKER END *
    ********************/

    /********************
    * URL VARIABLES (at the moment only for two words or more controller name) *
    ********************/

    $rootScope.AGEGROUP_URL = 'age_groups';
    $rootScope.AMOUNTTYPE_URL = 'amount_types';
    $rootScope.CONTACTTYPE_URL = 'contact_types';
    $rootScope.COURSETYPE_URL = 'course_types';
    $rootScope.DAYCLASS_URL = 'day_classes';
    $rootScope.ROLEPROFILE_URL = 'role_profiles';
    $rootScope.TIMECLASS_URL = 'time_classes';

    $rootScope.BANKTRANSFER_URL = 'bank_transfers';
    $rootScope.CREDITCARDPAYMENT_URL = 'credit_card_payments';
    $rootScope.CREDITCARDTYPE_URL = 'credit_card_types';
    $rootScope.PRODUCTCATEGORY_URL = 'product_categories';
    $rootScope.PRODUCTPRICE_URL = 'product_prices';

    $rootScope.COURSESCHEDULE_URL = 'course_schedules';

    $rootScope.COUNTRY_URL = 'countries';
    $rootScope.PROVINCE_URL = 'provinces';
    $rootScope.CITY_URL = 'cities';

    $rootScope.CLASSROOM_URL = 'classrooms';

    /********************
    * URL VARIABLES END *
    ********************/

    /********************
    * GLOBAL FUNCTION TO *
    * USE EVERYWHERE *
    ********************/

    $rootScope.delete = function(item, id, object){
      console.log(object);
      if (!object.withCollection) {
        object.withCollection = true;
      };
      Services.delete(item, id)
      .then(function(){
        if (object.withCollection) {
          object.collection.splice(object.index, 1);
        };
      });
    };

    $rootScope.formatTerm = function(term){
      return term.Number + '/' + term.Year + ' (' + $filter('date')(term.StartDate, 'MMM dd') + ' - ' + $filter('date')(term.EndDate, 'MMM dd') + ')';
    };

    $rootScope.absThis = function(number) {
      return Math.abs(number);
    }

    /********************
    * END *
    ********************/
  }
])
.value('cgBusyDefaults',{
  message:'Please Wait',
  backdrop: true,
  // templateUrl: '/views/templates/loading.html',
  minDuration: 7000
});
